package com.pla.googlecalendarviews;

import com.google.gdata.data.calendar.CalendarEntry;
import com.google.gdata.data.calendar.ColorProperty;
import com.google.gdata.data.calendar.HiddenProperty;
import com.google.gdata.data.calendar.SelectedProperty;

public class Calendar implements Comparable {

  private String title;
  private boolean hidden;
  private boolean selected;
  private String rgb;
  private boolean exists = false;
  private String calendarId;
  private CalendarEntry calendarEntry;

  public Calendar() {
  }

  public Calendar(CalendarEntry calendarEntry) {
    SelectedProperty selectedProperty = calendarEntry.getSelected();
    HiddenProperty hiddenProperty = calendarEntry.getHidden();
    ColorProperty colorProperty = calendarEntry.getColor();
    setTitle(calendarEntry.getTitle().getPlainText());
    setHidden(Boolean.valueOf(hiddenProperty.getValue()));
    setSelected(Boolean.valueOf(selectedProperty.getValue()));
    setRgb(colorProperty.getValue());
    setCalendarId(calendarEntry.getId());
    setCalendarEntry(calendarEntry);
  }

  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("Id: ");
    sb.append(getCalendarId()).append(" title: ");
    sb.append(title).append(" selected: ");
    sb.append(selected).append(" hidden: ");
    sb.append(hidden).append(" RGB: ");
    sb.append(rgb);
    return sb.toString();
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public boolean isHidden() {
    return hidden;
  }

  public void setHidden(boolean hidden) {
    this.hidden = hidden;
  }

  public boolean isSelected() {
    return selected;
  }

  public void setSelected(boolean selected) {
    this.selected = selected;
  }

  public String getRgb() {
    return rgb;
  }

  public void setRgb(String rgb) {
    this.rgb = rgb;
  }

  public boolean isExists() {
    return exists;
  }

  public void setExists(boolean exists) {
    this.exists = exists;
  }

  public String getCalendarId() {
    return calendarId;
  }

  public void setCalendarId(String calendarId) {
    this.calendarId = calendarId;
  }

  public CalendarEntry getCalendarEntry() {
    return calendarEntry;
  }

  public void setCalendarEntry(CalendarEntry calendarEntry) {
    this.calendarEntry = calendarEntry;
  }

  public int compareTo(Object o) {
    Calendar otherCalendar = (Calendar) o;
    if (title == null || otherCalendar.getTitle() == null) {
      return 0;
    } else {
      return title.compareToIgnoreCase(otherCalendar.getTitle());
    }
  }
}
